﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace ShoppingList
{
    public partial class EditListPage : PhoneApplicationPage
    {
        private string oldListName;

        public EditListPage()
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }
            InitializeComponent();

            oldListName = App.ViewModel.CurrentList.Name;
            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
        }

        private void btn_Save_Click(object sender, RoutedEventArgs e)
        {
            App.ViewModel.CurrentList.Date = DateTime.Now;
            NavigationService.GoBack();
        }

        private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (oldListName != null)
            {
                App.ViewModel.CurrentList.Name = oldListName;
            }
        }

        private void EditList_Loaded(object sender, RoutedEventArgs e)
        {
            ListName.Focus();
            ListName.SelectAll();
        }
    }
}